/*
 * @Author: 悦者生存 1002783067@qq.com
 * @Date: 2023-02-25 19:43:53
 * @LastEditors: 悦者生存 1002783067@qq.com
 * @LastEditTime: 2023-04-13 21:11:44
 * @FilePath: /koa2-ts-template/src/app/HttpException.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// src/core/HttpException.ts
// http异常
export class HttpException extends Error {
  public data: any;
  public code: number;
  constructor(data?: any) {
    super();
    this.code = 500;
    this.data = data;
  }
}

// http参数异常
export class ParameterException extends HttpException {
  constructor() {
    super();
    this.code = 400;
    this.data = '参数错误';
  }
}

// 授权失败
export class AuthFailed extends HttpException {
  constructor() {
    super();
    this.code = 401;
    this.data = '授权失败';
  }
}

// Forbbiden
export class Forbbiden extends HttpException {
  constructor() {
    super();
    this.code = 403;
    this.message = '禁止访问';
  }
}

// 404
export class NotFount extends HttpException {
  constructor() {
    super();
    this.code = 404;
    this.data = '资源未找到';
  }
}

// 查询失败
export class QueryFailed extends HttpException {
  constructor() {
    super();
    this.code = 500;
    this.message = '未查到匹配的数据';
  }
}

// 查询失败
export class DataBaseFailed extends HttpException {
  constructor(msg?: string) {
    super();
    this.code = 500;
    this.message = msg || '数据库出错';
  }
}
